package com.lkd.controller;


import com.lkd.constant.JwtClaimsConstant;
import com.lkd.dto.LoginDto;
import com.lkd.result.Result;
import com.lkd.service.UserService;
import com.lkd.utils.JwtUtil;
import com.lkd.vo.LoginUserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/api/user-service/user")
@Slf4j
public class LoginController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Result login(@RequestBody LoginDto dto){
        LoginUserVo userVo = userService.login(dto);
        HashMap<String,Object> cliaims = new HashMap<>();
        cliaims.put(JwtClaimsConstant.USER_ID,userVo.getUserId());
        cliaims.put(JwtClaimsConstant.USERNAME,userVo.getUserName());
        String token = JwtUtil.createJWT("wangjie",43200000L,cliaims);
        userVo.setToken(token);
        return Result.success(userVo);
    }

}
